<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TCP可靠性传输机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .number-circle {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 50%;
            color: white;
            font-weight: bold;
            font-size: 20px;
        }
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
        }
        .icon-box {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            margin-bottom: 1rem;
        }
        .highlight-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 600;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center">
                <h1 class="text-5xl font-bold mb-6">TCP 可靠性传输机制</h1>
                <p class="text-xl opacity-90 leading-relaxed">
                    深入解析传输控制协议如何在不可靠的网络环境中，通过精妙的设计确保数据传输的完整性、顺序性和准确性
                </p>
                <div class="mt-8 flex justify-center space-x-8">
                    <div class="text-center">
                        <i class="fas fa-shield-alt text-3xl mb-2"></i>
                        <p class="text-sm">可靠保障</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-sync-alt text-3xl mb-2"></i>
                        <p class="text-sm">智能重传</p>
                    </div>
                    <div class="text-center">
                        <i class="fas fa-stream text-3xl mb-2"></i>
                        <p class="text-sm">流量控制</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Introduction -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <p class="text-lg leading-relaxed text-gray-700 indent-8">
                    TCP（传输控制协议）通过一系列复杂的机制确保数据传输的可靠性。TCP被设计为一个面向连接的、可靠的协议，它能够在不可靠的网络环境中提供数据的完整性、顺序性和准确性。
                </p>
            </div>
        </div>
    </div>

    <!-- Visualization -->
    <div class="container mx-auto px-6 py-8">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-8 text-gray-800">TCP 可靠性机制全景图</h2>
            <div class="mermaid">
                graph TB
                    A[TCP可靠性传输] --> B[数据确认]
                    A --> C[重传机制]
                    A --> D[顺序保证]
                    A --> E[流量控制]
                    A --> F[拥塞控制]
                    A --> G[校验和]
                    A --> H[数据分段]
                    
                    B --> B1[发送ACK确认]
                    B --> B2[等待超时机制]
                    
                    C --> C1[超时重传]
                    C --> C2[快速重传]
                    
                    D --> D1[序列号机制]
                    D --> D2[数据重组]
                    
                    E --> E1[滑动窗口]
                    E --> E2[接收缓冲区]
                    
                    F --> F1[慢启动]
                    F --> F2[拥塞避免]
                    F --> F3[快速恢复]
                    
                    G --> G1[数据完整性验证]
                    G --> G2[错误检测]
                    
                    H --> H1[MSS分段]
                    H --> H2[按序重组]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style G fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style H fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="max-w-6xl mx-auto">
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                
                <!-- 1. 数据确认 -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle mr-4">1</div>
                        <div class="flex-1">
                            <h3 class="text-2xl font-bold mb-4 section-title">数据确认（Acknowledgment）</h3>
                            <div class="icon-box">
                                <i class="fas fa-check-double"></i>
                            </div>
                            <div class="space-y-4">
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-cog mr-2"></i>机制
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        TCP使用确认应答机制来确保数据包成功到达接收方。发送方在发送数据包后，会等待接收方的确认消息（ACK），以确认数据包的接收情况。
                                    </p>
                                </div>
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-info-circle mr-2"></i>工作原理
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        每当接收方收到一个数据包时，它会发送一个确认包（ACK），指明已经成功接收的数据字节的序号。如果发送方在超时时间内没有收到确认包，会重传数据包。
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 2. 重传机制 -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle mr-4">2</div>
                        <div class="flex-1">
                            <h3 class="text-2xl font-bold mb-4 section-title">重传机制（Retransmission）</h3>
                            <div class="icon-box">
                                <i class="fas fa-redo-alt"></i>
                            </div>
                            <div class="space-y-4">
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-cog mr-2"></i>机制
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        TCP使用重传机制来应对数据包丢失或损坏的情况。当发送方没有在预定的超时时间内收到接收方的确认包时，会重新发送未被确认的数据包。
                                    </p>
                                </div>
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-info-circle mr-2"></i>工作原理
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        TCP维护一个重传计时器，每个数据包在发送时会启动一个计时器。如果计时器超时且没有收到确认包，发送方会重新发送该数据包。这种机制确保了数据的可靠传输，即使在网络条件恶劣的情况下也能保证数据完整。
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 3. 数据顺序保证 -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle mr-4">3</div>
                        <div class="flex-1">
                            <h3 class="text-2xl font-bold mb-4 section-title">数据顺序保证（In-Order Delivery）</h3>
                            <div class="icon-box">
                                <i class="fas fa-sort-numeric-up"></i>
                            </div>
                            <div class="space-y-4">
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-cog mr-2"></i>机制
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        TCP确保数据包按发送顺序到达接收方。接收方在收到数据包后，会按照接收到的顺序将数据交给应用层，保持数据的顺序性。
                                    </p>
                                </div>
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-info-circle mr-2"></i>工作原理
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        每个TCP数据包都有一个序列号，接收方使用这些序列号将数据按正确的顺序重组。如果数据包到达的顺序不正确，接收方会暂时存储乱序的数据，并根据序列号将数据重新排序。
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- 4. 流量控制 -->
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                    <div class="flex items-start">
                        <div class="number-circle mr-4">4</div>
                        <div class="flex-1">
                            <h3 class="text-2xl font-bold mb-4 section-title">流量控制（Flow Control）</h3>
                            <div class="icon-box">
                                <i class="fas fa-tachometer-alt"></i>
                            </div>
                            <div class="space-y-4">
                                <div>
                                    <h4 class="font-semibold text-purple-700 mb-2">
                                        <i class="fas fa-cog mr-2"></i>机制
                                    </h4>
                                    <p class="text-gray-700 leading-relaxed">
                                        TCP通过流量控制机制来调节发送方的发送速率，以避免发送数据超出接收方的处理能力。
                                    </p>
                                </div>
                                <div>